﻿using System;
using System.Data;
using DFT.DB;
using DFT.Infos;

namespace DFT
{
    public partial class ManageTree : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable profilesTable = new DataTable("profiles");
            if (DBManager.GetAllProfilesUser(((UserInfo)Session["userInfo"]).UserId, ref profilesTable))
            {
                familyTreeView.Nodes.Clear();
                familyTreeView.Nodes.Add(Helper.BuildTree(profilesTable, -1));
                familyTreeView.ExpandAll();
            }
            else
            {
                String[] names = ((UserInfo)Session["userInfo"]).FullName.Split(' ');
                if (DBManager.CreateProfileUser(((UserInfo)Session["userInfo"]).UserId, -1, -1, names[0], names[names.Length - 1], "", "", "m", "", "", "", "", "", "", "", "", new Byte[0], ""))
                {
                    DBManager.GetAllProfilesUser(((UserInfo)Session["userInfo"]).UserId, ref profilesTable);
                    familyTreeView.Nodes.Add(Helper.BuildTree(profilesTable, -1));
                }
            }
        }

    }
}